import { defineConfig } from 'vite'
import { resolve } from "path"
import vue from '@vitejs/plugin-vue'
import Icons from "unplugin-icons/vite";
// element plus按需导入
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from "unplugin-icons/resolver";
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      include: [
        /\.[tj]sx?$/,
        /\.vue$/,
        /\.vue\?vue/,
      ],
      dts: true,
      imports: ['vue',
        'vue-router',
        'pinia',
        {
          // '@vueuse/core': [
          //   // named imports
          //   'useMouse', // import { useMouse } from '@vueuse/core',
          //   // alias
          //   ['useFetch', 'useMyFetch'], // import { useFetch as useMyFetch } from '@vueuse/core',
          // ],
          'axios': [
            // default imports
            ['default', 'axios'], // import { default as axios } from 'axios',
          ],
          'echarts': [
            // default imports
            'echarts', // import { default as echarts } from 'echarts',
          ],
        },
      ],
      // eslint报错解决
      eslintrc: {
        enabled: true, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      // element plus按需导入
      resolvers: [
        //自动导入element plus相关函数
        ElementPlusResolver(),
        // Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          prefix: "Icon",
        }),
      ]
    }),
    Components({
      resolvers: [
        IconsResolver({
          enabledCollections: ["ep"],
        }),
        //自动导入element plus组件
        ElementPlusResolver()
      ]
    }),
    Icons({
      autoInstall: true,
    }),
  ],
  // 配置根路径 
  resolve: {
    // ↓路径别名，主要是这部分 
    alias: {
      "@": resolve(__dirname, "./src")
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/assets/css/situation.scss";'
      }
    },
  },
  build: {
    chunkSizeWarningLimit: 1500, // 分块打包，分解块，将大块分解成更小的块
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
  server:{
    proxy:{
      '/api':{
        target:'http://172.18.38.19:8005',
        changeOrigin:true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  base: './',

})
